package com.ssm.hj.service.impl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ssm.hj.page.Page;
import com.ssm.hj.search.UserSearch;
import com.ssm.hj.service.UserService;
import com.ssm.hj.view.MemberView;
import com.ssm.mapper.UserMapper;
import com.ssm.pojo.User;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;
    @Override
    //登入查询
    public User loginQuery(String name, String password, HttpServletRequest request) throws Exception {
        User user = this.userMapper.loginQuery(name);
        if(user!=null){
            if(user.getPassword().equals(password.trim())){
                request.getSession().setAttribute("user",user);
                return user;
            }else{
                return null;
            }
        }
        return null;
    }

    @Override
    //查询所有用户
    public PageInfo<User> searchQueryUserAllService(Page<UserSearch> page) throws Exception {
        PageHelper.startPage(page.getPageNum(),page.getPageSize());
        return new PageInfo<User>(this.userMapper.queryUserAll(page.getSearchObj()));
    }

    @Override
    //修改用户状态
    public int updateStateService(int id, int state) throws Exception {
        return this.userMapper.updateState(id,state);
    }
}
